/**
 * 公共方法类
 */

//获取HTML中的参数
function request(name) {
	var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)");
	var r = window.location.search.substr(1).match(reg);
	if (r != null)
		return decodeURIComponent(r[2]);
	return null;
}


/**
 * ajax控件
 * 
 * @param c_name
 * @param value
 * @param expiredays
 * @returns
 */

var msg = null;

function $ajax(param) {
	// 开启加载提示
	param.ajaxStart = function() {
		if (assemblys.loadingMsg != null) {
			// console.log("开启提示");
			msg = assemblys.loadingMsg();
		}
	}

	// 关闭加载提示
	param.ajaxSuccess = function() {
		if (assemblys.closeLoadingMsg != null) {
			// console.log("关闭提示");
			assemblys.closeLoadingMsg(msg);
		}
	}
	param.dataType = param.dataType || "json";
	param.data = param.data || {};
	param.headers = param.headers || {};
	param.error = param.error || function(e, textStatus, errorThrown) {
		alert("服务器无响应，请联系管理员！错误信息:" + errorThrown);
	}

	var ETtoken = window.sessionStorage.getItem("ETtoken");
	if (!ETtoken) {
		ETtoken = window.localStorage.getItem("ETtoken");
	}
	param.headers.ETtoken = ETtoken;
	param.contentType = "application/x-www-form-urlencoded; charset=UTF-8";
	// 判断当前浏览器是否IE9以下
	if (navigator.appName == "Microsoft Internet Explorer" && parseInt(navigator.appVersion.split(";")[1].replace(/[ ]/g, "").replace("MSIE", "")) < 9) {
		jQuery.support.cors = true;
		if (!param.async) {
			param.async = true;
		}
		if (param.url.indexOf("?") > -1) {
			param.url += "&ETtoken=" + ETtoken;
		} else {
			param.url += "?ETtoken=" + ETtoken;
		}
		if (param.type && param.type.toLocaleUpperCase() == "POST") {
			param.contentType = "application/json;charset=UTF-8";
		}
	}
	$.ajax(param);
}